package com.jml.mapreduce.mapjoin;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;
import java.net.URI;

public class MapJoinDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        Job job = Job.getInstance(new Configuration());

        job.setJarByClass(MapJoinDriver.class);

        job.setMapperClass(MapJoinMapper.class);
        job.setNumReduceTasks(0);

        /**
         * 添加分布式缓存，把小表这个文件单独拿出来
         */
        job.addCacheFile(URI.create("file:///d:/input/pd.txt"));

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(NullWritable.class);
        /**
         * 这里还有一个文件，就是Order.txt，Map读取的都是大表数据
         */
        FileInputFormat.setInputPaths(job, new Path("D:\\tmp\\bigDate\\input"));
        FileOutputFormat.setOutputPath(job, new Path("D:\\tmp\\bigDate\\output"));

        boolean b = job.waitForCompletion(true);
        System.exit(b ? 0 : 1);
    }
}
